package com.ytjj.qmyx.admin.controller;

import com.google.common.collect.Maps;
import com.ytjj.common.api.CommonResult;
import com.ytjj.qmyx.admin.annotation.oplog.OperationProductLogger;
import com.ytjj.qmyx.admin.annotation.oplog.annotation.OperationLog;
import com.ytjj.qmyx.admin.constants.SysLogConstants;
import com.ytjj.qmyx.admin.service.ProductStarService;
import com.ytjj.qmyx.mall.model.ProductStar;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 *
 *
 * @Version: 1.0
 */
@RestController
@RequestMapping("/productStar")
@Slf4j
public class ProductStarController {

	@Resource
	private ProductStarService productStarService;

	@PostMapping("/syncInfo")
	public CommonResult syncInfo() {
		productStarService.syncInfo();
		return CommonResult.success();
	}

	@RequiresPermissions("productStar:selectStar")
	@GetMapping("/selectStar")
	public CommonResult selectStar(@RequestParam Integer productId) {
		return CommonResult.success(productStarService.getStarInfo(productId));
	}

	@RequiresPermissions("productStar:updateStar")
	@PostMapping("/updateStar")
	@OperationLog(optModule = SysLogConstants.PRODUCT, optType = SysLogConstants.OPERATION_UPDATE, desc = "设置商品星数")
	public CommonResult updateStar(@RequestBody ProductStar productStar) {
		try {
			Map<String, Object> map = Maps.newHashMap();
			map.put("msg", "设置商品星数");
			map.put("id",productStar.getProductId());
			map.put("价格星数",productStar.getPriceStar());
			map.put("质量星数",productStar.getQualityStar());
			map.put("实物相符星数",productStar.getMatchStar());
			OperationProductLogger.log(map);
		} catch (Exception e) {
			log.error("拼装日志信息异常{}", e);
		}

		productStarService.updateStarInfo(productStar);
		return CommonResult.success();
	}

}
